#!/usr/bin/env python3
import sys

args = sys.argv[1:]

strip = False
if '--strip' in args:
  args.remove('--strip')
  strip = True

append = str.encode(args[0]).decode('unicode-escape')
files = args[1:]

append = append.encode('utf8')

for filename in files:
  try:
    with open(filename, 'rb') as f:
      data = f.read()
      if strip:
        data = data.strip()
      sys.stdout.buffer.write(data)
    sys.stdout.buffer.write(append)
    sys.stdout.buffer.flush()
  except:
    import traceback
    traceback.print_exc()
